home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15977 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.9 KB  |  59 lines

  1. Path: news.nyu.edu!schonberg!dewar
  2. From: dewar@cs.nyu.edu (Robert Dewar)
  3. Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++,comp.edu
  4. Subject: Re: ANSI C and POSIX (was Re: C/C++ knocks the crap out of Ada)
  5. Date: 8 Apr 1996 21:13:48 -0400
  6. Organization: Courant Institute of Mathematical Sciences
  7. Message-ID: <dewar.829012027@schonberg>
  8. References: <JSA.96Feb16135027@organon.com> <dewar.828757752@schonberg> <danpop.828819479@rscernix> <dewar.828879781@schonberg> <4k9qhe$65r@solutions.solon.com> <dewar.828936837@schonberg> <828964950snz@genesis.demon.co.uk> <4kbfup$2vd@news1.mnsinc.com> <4kbl5i$p3@mordred.gatech.edu> <4kbr5q$j1l@mulga.cs.mu.OZ.AU>
  9. NNTP-Posting-Host: schonberg.cs.nyu.edu
  10. X-Newsreader: NN version 6.5.0 (NOV)
  11.  
  12. Fergus says
  13.  
  14. "Nope, you've got cause and effect backwards.  There's no way to make
  15. undefined behavior portable *because* it is undefined.  If a language
  16. has constructs with undefined behaviour, this will lead to portability
  17. problems.  But some languages have fewer areas of undefined behaviour
  18. than others.  Some languages don't have any undefined behaviour at
  19. all."
  20.  
  21. True enough, but this is only achievable by going to a fairly high
  22. level of abstraction. For example SNOBOL4 (or SPITBOL) programs
  23. are totally portable, with no undefined behavior at all.
  24.  
  25. But if you have a language that can twiddle bits at a low level, it is
  26. hard to see how undefined behavior could be eliminated completely.
  27.  
  28. It is definitely true that constructs with undefined (or non-deterministic)
  29. behavior, can lead to portability problems. Remember portable programs
  30. are portable by definition -- it's possible to write portable programs
  31. in any language. Portability problems are precisely caused by constructs
  32. that render progams non-portable. This is obvious, but worth saying, 
  33. because for example Peter tends to say "What portability problems,
  34. your code is just wrong :-)"
  35.  
  36. Back to non-determinism. A language can have totally defined semantics
  37. and still have non-deterministic semantics. For example in SETL, a language
  38. with no undefined semantics:
  39.  
  40.    x := arb {1,2,3,4};
  41.  
  42. selects an arbitrary element of the set, and puts any of 1,2,3,4 in X.
  43. The semantics of SETL is well defined (although as usual the presence
  44. of such non-determinism complicates the formal semantics). However,
  45. it is now possible to write non-portable SETL programs that incorrectly
  46. depend on "knowing" that in practice the compiler in use always implements
  47. arb by selecting the minimum element (a perfectly correct implementation,
  48. arb does not mean random!).
  49.  
  50. A similar case arises in Ada with the select statement, which is free
  51. to select any open alternative non-determinisitically, or with the
  52. semantics of expression evaluation, where it is non-determinstic
  53. whether the right or left operand of an operator is evaluated first.
  54. The second case could be eliminated from the language, but anyting
  55. invollving timing is likely to lead to some non-eliminatable
  56. non-determinism.
  57. dp
  58.  
  59.